<?php
class Pmc {
    const GENERAL = 300;// 5分钟
    const LONG= 18600;//24 小时
    private $hosts;    

    public function __construct($hosts){
        $this->hosts = $hosts;
    }
    
    public function __get($name){
        if ($name === 'mch'){
            $this->mch = memcache_connect($this->hosts[0]['host'], $this->hosts[0]['port']);
            array_shift($this->hosts);
            foreach ($this->hosts as $host) {
            	memcache_add_server($this->mch, $host['host'], $host['port']);
            }
            return $this->mch;
        }
    }
    
    public function get($key){
        return memcache_get($this->mch, $key);
    }
    
    public function add($key, $val, $expire=30){
        return memcache_add($this->mch, $key, $val, false, $expire);
    }
    
    public function delete($key){
        return memcache_delete($this->mch, $key);
    }
    
    public function decrement($key, $step=1){
        return memcache_decrement($this->mch, $key, $val);
    }
    
    public function increment($key, $step=1){
        return memcache_increment($this->mch, $key, $val);
    }
    
    public function set($key, $val, $expire=300) {
    	return memcache_set($this->mch, $key, $val, false, $expire);
    }
    
    public function replace($key, $val, $expire=300){
        return memcache_replace($this->mch, $key, $val, false, $expire);
    }
}